package com.ieng.ormosia.common.utils;

import com.ieng.ormosia.common.vo.ResponseData;
import org.springframework.http.HttpStatus;

public class ActionR {

    public static ResponseData send(String message){
        ResponseData responseData = new ResponseData();
        responseData.setCode(0);
        responseData.setMsg(message);
        return responseData;
    }

    public static ResponseData success(Object data){
        ResponseData responseData = new ResponseData();
        responseData.setCode(0);
        responseData.setData(data);
        responseData.setMsg("success");
        return responseData;
    }

    public static ResponseData error(String message){
        ResponseData responseData = new ResponseData();
        responseData.setCode(-1);
        responseData.setMsg(message);
        return responseData;
    }

    public static ResponseData success(int status, Object data, String message){
        ResponseData responseData = new ResponseData();
        responseData.setCode(status);
        responseData.setData(data);
        responseData.setMsg(message);
        return responseData;
    }

    public static ResponseData error(int status, String message){
        ResponseData responseData = new ResponseData();
        responseData.setCode(status);
        responseData.setMsg(message);
        return responseData;
    }

    public static ResponseData failure(HttpStatus status, String message){
        ResponseData responseData = new ResponseData();
        responseData.setCode(status.value());
        responseData.setMsg(message == null || "".equals(message) ? status.getReasonPhrase() : message);
        return responseData;
    }

}
